/* Copyright (C) 2007-2008  klevgert  http://code.google.com/p/db4o-netbeans/

This file is part of the db4o-netbeans module suite.

db4o-netbeans is free software; you can redistribute it and/or modify it under
the terms of version 2 of the GNU General Public License as published
by the Free Software Foundation and as clarified by db4objects' GPL 
interpretation policy, available at
http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
Suite 350, San Mateo, CA 94403, USA.

db4o-netbeans is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */

package com.db4o.nb.api.impl;

import com.db4o.nb.api.QueryData;
import org.w3c.dom.Element;

/**
 * This is the base class for query data objects.
 * @author klevgert
 */
public class AbstractQueryImpl implements QueryData {
  
  private static String ATTR_NAME = "name";
  private static String ATTR_DESC = "description";
  private static String ATTR_TYPE = "type";
  private static String ATTR_KIND = "kind";
  private static String ATTR_EXPR = "expression";

  /**
   * the encapsulated xml query element
   */
  protected Element element; 
  
  /**
   * Creates a new instance of AbstractQueryImpl.
   * @param element   xml dom element used by this instance.
   */
  public AbstractQueryImpl(Element element) {
    this.element = element;
  }

  /**
   * Gets the underlying xml element.
   * @return xml element dom object
   */
  Element getElement() {
    return this.element;
  }
  
  /**
   * Gets the name of the query.
   * @return name of query.
   */
  public String getName() {
    return this.element.getAttribute(AbstractQueryImpl.ATTR_NAME);
  }

  /**
   * Gets a description for the query.
   * @return descriptive text for the query.
   */
  public String getDescription() {
    return this.element.getAttribute(AbstractQueryImpl.ATTR_DESC);
  }

  /**
   * Gets the type of objects to query for.
   * @return full qualified name of the object type. 
   */
  public String getType() {
    return this.element.getAttribute(AbstractQueryImpl.ATTR_TYPE);
  }

  /**
   * Gets the kind of a query, e.g. SQL, SODA, ...
   * @return kind of a query as a string. 
   */
  public String getKind() {
    return this.element.getAttribute(AbstractQueryImpl.ATTR_KIND);
  }

  /**
   * Gets the expression as used for text based query objects, such as SQL.
   * @return expression text as a string.
   */
  public String getExpression() {
    return this.element.getAttribute(AbstractQueryImpl.ATTR_EXPR);
  }

  /**
   * Sets the name of the query.
   * @param name   name of query.
   */
  public void setName(String name) {
    this.element.setAttribute(AbstractQueryImpl.ATTR_NAME, name);
  }

  /**
   * Sets a descriptive text for the query.
   * @param desc   description of query.
   */
  public void setDescription(String desc) {
    this.element.setAttribute(AbstractQueryImpl.ATTR_DESC, desc);
  }

  /**
   * Sets the type of objecs to query for.
   * @param type    full qualified name of the object type.
   */
  public void setType(String type) {
    this.element.setAttribute(AbstractQueryImpl.ATTR_TYPE, type);
  }

  /**
   * Sets the kind of query.
   * @param kind   kind of query as a text, like 'SQL'...
   */
  public void setKind(String kind) {
    this.element.setAttribute(AbstractQueryImpl.ATTR_KIND, kind);
  }

  /**
   * Sets the expression text for text based query kinds, such as SQL.
   * @param expression   expression text.
   */
  public void setExpression(String expression) {
    this.element.setAttribute(AbstractQueryImpl.ATTR_EXPR, expression);
  }
  
}
